package com.android.common.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 新建数据库及表
 */
public class CommonDBCreator extends SQLiteOpenHelper {
    CommonDBCreator(Context context) {
        super(context, DBConfig.COMMON_DATABASE_NAME, null, DBConfig.DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + DBConfig.LOGIN_TABLE_NAME +"(" +
            Columns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
            Columns.USER_CREDENTIAL_KEY + " TEXT," +
            Columns.APP_CREDENTIAL_KEY + " TEXT" +
            ");");

        db.execSQL("CREATE TABLE " + DBConfig.ENV_TABLE_NAME +"(" +
            Columns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
            Columns.ENV_SERVER_API_ADDRESS + " TEXT," +
            Columns.ENV_H5_ADDRESS + " TEXT," +
            Columns.ENV_OTHER_ADDRESS + " TEXT" +
            ");");
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + DBConfig.LOGIN_TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + DBConfig.TMS_TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + DBConfig.ENV_TABLE_NAME);
        onCreate(db);
    }
}

